package com.guangyunl.b_array;
// 数组扩容
//需求:
//    定义一个数组: int[] arr1 = {1,2,3,4,5}
//        将数组由原来的长度扩容到10
//方式一:
//    创建一个和arr1 一样的数组存储arr1的数据，然后重新定义arr1的长度，再把数据存到新的arr1上
public class Demo08_01ArrayExpand {
    public static void main(String[] args) {
        // 定义数组
        int[] arr1 = {1,2,3,4,5};
        int[] arr2 = new int[arr1.length];
        System.arraycopy(arr1, 0, arr2, 0, arr1.length);
        //扩容arr1
        arr1 = new int[10];
        System.arraycopy(arr2, 0, arr1, 0, arr2.length);
        // 输出arr1[]的数据以及长度
        for (int i = 0; i < arr1.length; i++) {
            System.out.println("arr1[" + i + "] = " + arr1[i]);
        }
        System.out.println("arr1的长度为: " + arr1.length);

    }
}

/*
arr1[0] = 1
arr1[1] = 2
arr1[2] = 3
arr1[3] = 4
arr1[4] = 5
arr1[5] = 0
arr1[6] = 0
arr1[7] = 0
arr1[8] = 0
arr1[9] = 0
arr1的长度为: 10
 */